package com.zhiyou100.loans.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zhiyou100.loans.dao.RateDao;
import com.zhiyou100.loans.dao.impl.RateDaoImpl;
import com.zhiyou100.loans.model.Rate;
import com.zhiyou100.loans.service.RateService;

import net.sf.json.JSONArray;

public class RateServiceImpl implements RateService {
	RateDao rd = new RateDaoImpl();
	@Override
	public JSONArray select() {
		ResultSet  rs = rd.select();
		List<Rate> list = new ArrayList<>();
		try {
			while(rs.next()){
				Rate r = new Rate();
				r.setId(rs.getInt("id"));
				r.setDuration(rs.getInt("duration"));
				r.setMonthRate(rs.getDouble("monthrate"));
				list.add(r);
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return JSONArray.fromObject(list);
	}

}
